//
//  DateViewController.m
//  Travel assistant
//
//  Created by lanou3g on 16/3/5.
//  Copyright © 2016年 旅游助手. All rights reserved.
//

#import "DateViewController.h"

@interface DateViewController ()
@property (nonatomic, strong) NSDate *date;
@property (nonatomic, strong) FDCalendar *calendarView;

@end

@implementation DateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setViews];
}
- (void)setViews{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar_arrow_down@2x"] style:UIBarButtonItemStyleDone target:self action:@selector(rightBarButtonItemAction:)];
    
    self.calendarView = [[FDCalendar alloc] initWithCurrentDate:[NSDate date]];
    CGRect frame = self.calendarView.frame;
    frame.origin.y += 10;
    self.calendarView.frame = frame;
    [self.view addSubview:self.calendarView];
    __weak typeof(self) __self = self;
    self.calendarView.block = ^(NSDate *date){
        __self.date = [[DateHelper sharedDateHelper] dayDateWithDate:date AddHours:YES];
        NSLog(@"000000选择的时间为%@",__self.date);
    };

    
    
    
    
}
- (void)rightBarButtonItemAction:(UIBarButtonItem *)sender{
    /**选择日期早于今天，则不能添加*/
    if ([self.date timeIntervalSince1970] < [[[DateHelper sharedDateHelper] dayDateWithDate:[NSDate date] AddHours:NO] timeIntervalSince1970]) {
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"选择的日期不能早于今日" preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [self.navigationController presentViewController:alertController animated:YES completion:nil];
    } else {
        __weak typeof(self) __self = self;
        [self.navigationController  dismissViewControllerAnimated:YES completion:^{
            if (self.passDateBlock) {
                self.passDateBlock(__self.date);
            }
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
